export function getUserTypeLabel (type) {
  switch (type) {
    case 'user':
      return '用户';
    case 'post':
      return '岗位'
    case 'company':
      return '公司';
    case 'depart':
      return '部门'
    case 'role':
      return '角色'
    case 'applyUserId':
      return '发起人'
    case 'previousExecutor':
      return '上一步执行人'   
    case 'currentUserId':
      return '当前登录用户' 
    case 'sql':
      return 'sql脚本'   
    case 'custom':
      return '自定义条件'      
  }
}

export async function getGridLabel ($http, queryEntityUrl, labelValue, labelName, newVal) {
  var selectData = []
  let ids = newVal.split(',')
  for(let i=0;i <ids.length; i++){
    let value = ids[i]
    if(value){
      var data =  await $http.get(`${queryEntityUrl}?${labelValue}=${value}`)
      if (data[labelValue] !== '') {
        selectData.push(data)
      }
    }
   
  }
  return selectData.map(item => { return item[labelName] }).join(',')
}

export function getRoleLabel ($http, newVal) {
  return getGridLabel ($http, '/sys/role/queryById', 'id', 'name',  newVal)
}

export function getPostLabel ($http, newVal) {
  return getGridLabel ($http, '/sys/post/queryById', 'id', 'name',  newVal)
}

export function getUserLabel ($http, newVal) {
  return getGridLabel ($http, '/sys/user/queryById', 'id', 'name', newVal)
}


export function getDepartLabel ($http, newVal) {
  return getGridLabel ($http, '/sys/office/queryById', 'id', 'name', newVal)
}


export default {getUserTypeLabel, getRoleLabel, getPostLabel, getUserLabel, getDepartLabel}
